import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class elevator here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class dropper  extends object
{
    Zony z;
    boolean shaking=false,dropping=false,stand=true,t;
    int counter=0,velY=0,center;
    
    public dropper(boolean type){
        t=type;
    } 
    protected void addedToWorld(World world)
    {
        if(t)
            setImage(((it)getWorld()).getDropper());
        else
            setImage(((it)getWorld()).getPLatform());
        z = (Zony) getWorld().getObjects(Zony.class).get(0);
        center=getX();
    }  
    
    public void act() 
    {
        counter++;
        stand = z.getY()<getY()-16;
        if(!shaking && !dropping && Math.abs(z.getX()-getX())<15 && z.getY()>getY()-20 && z.getY()<getY()){
            shaking=true;
            counter=0;
        }
        if(shaking){
            setLocation(center + (counter%9)/3-1,getY());
            if(counter==20){
                shaking = false;
                dropping=true;
            }
        }
        if(dropping){
            setLocation(center,getY()+velY);
            if(counter%4==0)velY++;
            if(!((it)getWorld()).ok(center,getY()+5) || ((it)getWorld()).kill(center,getY()+5)){
                explode();
                return;
            }
        }
  
    }    
    
    public void explode(){
        double ang,amp;
            for(int f=0;f<13;f++){
                ang = 3.14159*Math.random();
                amp = 2*Math.random()+1;
                getWorld().addObject(new projectile(3,amp*Math.cos(ang),-amp*Math.sin(ang),true),getX(),getY());
            }
        getWorld().removeObject(this);
    }
    
    public boolean stand(){
        return stand;
    }
    
    
}
